package com.fankui.serviceedu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fankui.commonutils.R;
import com.fankui.serviceedu.entity.EduCourse;
import com.fankui.serviceedu.entity.Teacher;
import com.fankui.serviceedu.service.EduCourseService;
import com.fankui.serviceedu.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName EduTeacherFrontController
 * Description TODO
 * Date 2023/12/8 12:24
 *
 * @Author 范奎
 * @Since JDK 11
 */
@Api(description = "前台名师")
@RestController
@RequestMapping("/eduservice/teacherfront")
public class EduTeacherFrontController {
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    @ApiOperation(value = "查询分页名师数据")
    @PostMapping("getTeacherFrontList/{current}/{size}")
    public R getTeacherFrontList(@ApiParam(name = "current", value = "当前页", required = true) @PathVariable long current,
                                 @ApiParam(name = "size", value = "每页记录数", required = true) @PathVariable long size) {
        Page<Teacher> pageTeacher = new Page<>(current, size);
        Map<String, Object> map = teacherService.getTeacherFrontList(pageTeacher);
        return R.ok().data(map);
    }

    @ApiOperation(value = "获取讲师详情")
    @GetMapping("getTeacherFront/{teacherId}")
    public R getTeacherFront(@ApiParam(name = "teacherId", value = "讲师id", required = true) @PathVariable String teacherId) {
        Teacher teacher = teacherService.getById(teacherId);
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);
        Map<String, Object> map = new HashMap<>();
        map.put("teacher", teacher);
        map.put("courseList", courseList);
        return R.ok().data(map);
    }
}
